/**
 * @author 徐楠
 * @date 2021/12/2 20:52
 * @version 1.0
 */

package com.xunan.likou;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;

public class Solution {
    public static void main(String[] args) {
        int length = lengthOfLongestSubstring("dvdf");
        System.out.println(length);
    }

    public static int lengthOfLongestSubstring(String s) {

        int n = s.length();
        int answer = 0;
        int length;
        Map<Character, Integer> map = new HashMap<>();
        for (int end = 0, start = 0; end < n; end++) {
            char oneChar = s.charAt(end);
            if (map.containsKey(oneChar)) {
                start = Math.max(map.get(oneChar), start);
            }
            length = end - start + 1;
            answer = Math.max(answer, length);
            map.put(s.charAt(end), end + 1);
        }
        return answer;


    }
}
